package day06;

import java.util.Scanner;

public class homework04 {
   /*
	 *  4.
             *  	dajlskldjsalkdjsalkda
	 *  	djaskldjlsalk
	 *  相同的最长的字符串为：skldj
	 **/
   public static void main(String[] args) {
	   Scanner sc=new Scanner(System.in);
	   System.out.println("输入第一个字符串:");
	   String str1=sc.next();
	   System.out.println("输入第二个字符串:");
	   String str2=sc.next();
	   String samestring=getmaxsamestring(str1, str2);
	   System.out.println(samestring);
   }
	public static String getmaxsamestring(String str1, String str2) {
		String maxstr = (str1.length() > str2.length()) ? str1 : str2;
		String minstr = (str1.length() < str2.length()) ? str1 : str2;
		int len = minstr.length();
		String samestring;
		for (int i = len; i > 1; i--) {
			for (int start = 0, end = i; end <= len; start++,end++) {
				samestring = minstr.substring(start, end);
				if (maxstr.indexOf(samestring) > 0) {
					return samestring;
				}
			}
		}
		return null;
	}
}
